﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOMS.Utility;
using BOMS.DBUtility;
using System.Data;
namespace BOMS.DAL
{
    public class WarningHistory
    {
        public static DataSet getWarningHistory(string equipid, string batterygroup,string batteryId, string beginWarningtime,string endWarningtime, string warningstatus)
        {
            string str_Sql = "select a.*,b.HostName from s_warning a left outer join M_SubLans b on a.EquipID=b.Mac where isactive=0 and warningtime>='" + beginWarningtime + "' and warningtime<='" + endWarningtime + "'";

            if(warningstatus!="全部类型"){
                str_Sql = str_Sql + " and warningstatus='" + warningstatus + "'";

            }
            if(equipid!=""){
                str_Sql = str_Sql + " and equipid='" + equipid + "'";
            }
            if(batterygroup!=""){
                str_Sql = str_Sql + " and batterygroup='" + batterygroup + "'";
            }
            if (batteryId != "")
            {
                str_Sql = str_Sql + " and batteryId='" + batteryId + "'";
            }
            DataSet ds = DBUtility.DbHelper.Query(str_Sql);
            return ds;
        }

        public static DataTable getWarningProcessInfo(int warningId)
        {
            DataTable dt = new DataTable();
            if (DbHelper.DBType == "MsSql")
            {
                string str_Sql = "select top 1 w.*,u.name from warningdealwith w ,sysuser u where w.creatorid=u.id and warningid=" + warningId + " order by w.id desc";
                dt = DBUtility.DbHelperSQL.Rt_Table(str_Sql);
            }
            else if (DbHelper.DBType == "MySql")
            {
                string str_Sql = "select  w.*,u.name from warningdealwith w ,sysuser u where w.creatorid=u.id and warningid=" + warningId + " order by w.id desc limit 1";
                dt = DBUtility.DbHelperMySql.Rt_Table(str_Sql);
            }
            return dt;
        }
    }
}
